/**
 * Created by 17-xuyulin on 2017/3/10.
 */
import $ from 'jquery'
import Vue from 'vue'
export const Event = new Vue()
Vue.prototype.openMenu = function (name, title, content) {
  let menu = {
    name: name,
    title: title,
    content: content
  }
  Event.$emit('openMenu', menu)
}
let API_ROOT = (process.env.NODE_ENV === 'production') ? '' : 'http://127.0.0.1:8082'
export function get (url, success, error) {
  $.ajax({
    url: API_ROOT + url,
    type: 'get',
    success: success,
    error: function (t) {
      if (t.responseText !== undefined && t.responseText.indexOf('login') !== -1) {
        window.location.href = '/login'
        return
      }
      error(t)
    }
  })
}
export function post (url, data, success, error) {
  $.ajax({
    url: API_ROOT + url,
    type: 'post',
    contentType: 'application/json; charset=utf-8',
    dataType: 'json',
    data: JSON.stringify(data),
    success: success,
    error: function (t) {
      if (t.responseText !== undefined && t.responseText.indexOf('login') !== -1) {
        window.location.href = '/login'
        return
      }
      error(t)
    }
  })
}
export const PAGESIZE = 500
export const PAGESIZES = [10, 50, 100, 300, 500]
export const PAGELAYOUT = 'total, sizes, prev, pager, next, jumper'
export function go (url) {
  window.location.href = url
}
export const ACCOUNT_NAV_LIST = [
  {
    name: 'changePassword',
    href: '/password'
  }, {
    name: 'logout',
    href: '/logout'
  }
]
export const LEFT_MENU_NAV_LIST = [
  {
    name: 'portal',
    title: '后台管理',
    icon: 'el-icon-menu',
    list: [
      {
        name: 'listDemo',
        title: '列表Demo',
        component: require(`./pages/list/ListDemo.vue`),
        icon: 'el-icon-setting'
      }, {
        name: 'chart',
        title: '图表Demo',
        component: require(`./pages/echart/EchartDemo.vue`),
        icon: 'el-icon-setting'
      }, {
        name: 'item',
        title: '物品管理',
        component: require(`./pages/item/Index.vue`),
        icon: 'el-icon-setting'
      }, {
        name: 'cart3',
        title: '购物车3',
        href: '/pages/Test',
        component: require(`./pages/Test.vue`),
        icon: 'el-icon-setting'
      }, {
        name: 'cart4',
        title: '购物车4',
        href: '/pages/Test',
        component: require(`./pages/Test.vue`),
        icon: 'el-icon-setting'
      }, {
        name: 'cart5',
        title: '购物车5',
        href: '/pages/Test',
        component: require(`./pages/Test.vue`),
        icon: 'el-icon-setting'
      }, {
        name: 'cart6',
        title: '购物车6',
        href: '/pages/Test',
        component: require(`./pages/Test.vue`),
        icon: 'el-icon-setting'
      }, {
        name: 'cart7',
        title: '购物车7',
        href: '/pages/Test',
        component: require(`./pages/Test.vue`),
        icon: 'el-icon-setting'
      }, {
        name: 'cart8',
        title: '购物车8',
        href: '/pages/Test',
        component: require(`./pages/Test.vue`),
        icon: 'el-icon-setting'
      }, {
        name: 'cart9',
        title: '购物车9',
        href: '/pages/Test',
        component: require(`./pages/Test.vue`),
        icon: 'el-icon-setting'
      }, {
        name: 'cart10',
        title: '购物车10',
        href: '/pages/Test',
        component: require(`./pages/Test.vue`),
        icon: 'el-icon-setting'
      }, {
        name: 'cart11',
        title: '购物车11',
        href: '/pages/Test',
        component: require(`./pages/Test.vue`),
        icon: 'el-icon-setting'
      }, {
        name: 'cart12',
        title: '购物车12',
        href: '/pages/Test',
        component: require(`./pages/Test.vue`),
        icon: 'el-icon-setting'
      }, {
        name: 'cart13',
        title: '购物车13',
        href: '/pages/Test',
        component: require(`./pages/Test.vue`),
        icon: 'el-icon-setting'
      }, {
        name: 'cart14',
        title: '购物车14',
        href: '/pages/Test',
        component: require(`./pages/Test.vue`),
        icon: 'el-icon-setting'
      }, {
        name: 'cart15',
        title: '购物车15',
        href: '/pages/Test',
        component: require(`./pages/Test.vue`),
        icon: 'el-icon-setting'
      }, {
        name: 'cart16',
        title: '购物车16',
        href: '/pages/Test',
        component: require(`./pages/Test.vue`),
        icon: 'el-icon-setting'
      }, {
        name: 'cart17',
        title: '购物车17',
        href: '/pages/Test',
        component: require(`./pages/Test.vue`),
        icon: 'el-icon-setting'
      }, {
        name: 'cart18',
        title: '购物车18',
        href: '/pages/Test',
        component: require(`./pages/Test.vue`),
        icon: 'el-icon-setting'
      }, {
        name: 'cart19',
        title: '购物车19',
        href: '/pages/Test',
        component: require(`./pages/Test.vue`),
        icon: 'el-icon-setting'
      }, {
        name: 'cart20',
        title: '购物车20',
        href: '/pages/Test',
        component: require(`./pages/Test.vue`),
        icon: 'el-icon-setting'
      }
    ]
  }
]
export const HEADER_MENU_NAV_LIST = [
  {
    name: 'setting',
    href: '/',
    active: false
  }, {
    name: 'home',
    href: '/',
    active: false
  }, {
    name: 'home2',
    href: '/',
    active: false
  }, {
    name: 'home3',
    href: '/',
    active: false
  }
]
export const LANGUAGE_OPS_LIST = [
  {
    name: 'cn'
  }, {
    name: 'en'
  }
]
